﻿using Newtonsoft.Json;
using static System.Runtime.CompilerServices.RuntimeHelpers;

namespace WebApi2.WebApi
{
    public static class DeviceAdapterSimulation
    {
        public static RouteGroupBuilder MapDeviceAdapterApiV1(this IEndpointRouteBuilder app)
        {
            var api = app.MapGroup("ddckapi/Devices");
            api.MapGet("ping", () =>
            {
                return TypedResults.Ok(new { Errcode = 0, Errmsg = "ok", Data = new { State = true } });
            });
            api.MapPost("status", (StatusInputModel input) =>
            {
                return TypedResults.Ok(new
                {
                    Errcode = 0,
                    Errmsg = "ok",
                    Data = new Dictionary<string, Dictionary<string, StatusValue>>
                    {
                        { "status",
                            new Dictionary<string, StatusValue> {
                                { "remote_control", new StatusValue ("2025-05-10 12:00:01","1") },
                                { "speed_cur", new StatusValue ("2025-05-10 12:00:01","1.23") },
                                { "converter_control", new StatusValue ("2025-05-10 12:00:01","1") }
                            }
                        }
                    }
                });
            });
            return api;
        }
    }
    public class StatusInputModel
    {
        /// <summary>
        /// 参数
        /// </summary>
        [JsonProperty("keys")]
        public List<string> Keys { get; set; } = new List<string>();
    }
    public record StatusValue(string Time, string Value);
}
